package com.itbaizhan.controller;

import com.alibaba.cloud.ai.dashscope.audio.synthesis.SpeechSynthesisModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.alibaba.cloud.ai.dashscope.chat.MessageFormat;
import com.itbaizhan.helper.FrameHelper;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.model.Media;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 视频转文字
 */
@RestController
public class VideoController {

    @Autowired
    private ChatModel chatModel;


    /**
     * 视频转文字
     * @param file 视频
     * @param message 提示词
     * @return
     */
    @PostMapping("/video")
    public String video(MultipartFile file, String message){

        // 1、视频图片
        List<Media> mediaList = FrameHelper.load(file);
        UserMessage userMessage = new UserMessage(message,mediaList);
        userMessage.getMetadata().put(DashScopeChatModel.MESSAGE_FORMAT, MessageFormat.VIDEO);

        // 2、发送请求
        ChatResponse chatResponse = chatModel.call(new Prompt(userMessage, DashScopeChatOptions.builder()
                .withModel("qwen-vl-max-latest")
                .withMultiModel(true).build()));

        return chatResponse.getResult().getOutput().getContent();


    }




}
